<?php
function data_sql_insert($tbl, $arr)
{
  $fields = array_keys($arr);
  $values = array_values($arr);

  foreach ($values as $key => $val) {

    if (\strpos($val, '@') !== false) {
      $values[$key] = $val;
      continue;
    }

    $values[$key] = "'" . $val . "'";
  }

  return "INSERT INTO " . $tbl . " (" . array_str($fields) . ") VALUES (" . array_str($values) . ");";
}

function data_sql_update($tbl, $arr, $where)
{
  $sql_set = array();
  foreach ($arr as $key => $val) {
    $val = (\strpos($val, '@') !== false) ? $val : "'" . $val . "'";
    $sql_set[] = $key . "=" . $val;
  }

  return "UPDATE " . $tbl . " SET " . \array_str($sql_set) . " WHERE $where;";
}

function data_sql_delete($tbl, $id)
{
  return "DELETE FROM " . $tbl . " WHERE id IN ($id);";
}

function data_sql_delete_common($tbl, $col, $val)
{
  return "DELETE FROM " . $tbl . " WHERE $col = $val;";
}